import { getProductDetail, getProductComments } from '@/services/product';

export default {
  namespace: 'productDetail',
  state: {
    detail: {},
    comments: []
  },
  reducers: {
    setProDetail(state, { payload }) {
      // console.log(payload);
      return {
        ...state,
        detail: payload
      }
    },
    setProComments(state, { payload }) {
      console.log(payload);
      return {
        ...state,
        comments: payload
      }
    }
  },
  effects: {
    *getProDetail({ payload }, { call, put }) {
      const res = yield call(getProductDetail, payload);
      // console.log(res);
      yield put({
        type: 'setProDetail',
        payload: res[0]
      })
    },
    *getProComments({ payload }, { call, put }) {
      const res = yield call(getProductComments, payload);
      console.log(res);
      yield put({
        type: 'setProComments',
        payload: res
      })
    }

  },
}